//! file: private.cpp

#include <iostream>
#include <string>
using namespace std;
#include "gtest/gtest.h"
#define private	 public
#include "List02.hpp"

TEST(newNodeTest, content)
{
	List<int> lst;
	List<int>::iterator pos;

	pos	= lst.newNode(1);
	EXPECT_EQ(*pos, 1);
	lst.destroyNode(pos);

	pos = lst.newNode(10);
	EXPECT_EQ(*pos, 10);
	lst.destroyNode(pos);

	List<string> str_lst;
	List<string>::iterator str_pos;

	str_pos = str_lst.newNode();
	EXPECT_STREQ((*str_pos).c_str(), "");
	str_lst.destroyNode(str_pos);

	str_pos = str_lst.newNode("Hello, the world");
	EXPECT_STREQ((*str_pos).c_str(), "Hello, the world");
	str_lst.destroyNode(str_pos);
}

TEST(insertNodeTest, content)
{
	List<int> lst;

	List<int>::iterator pos = lst.insertNode(lst.end(), 1);	
	EXPECT_EQ(pos, lst.begin());
	EXPECT_EQ(*lst.begin(), 1);

	pos = lst.insertNode(lst.begin(), 2);
	EXPECT_EQ(pos, lst.begin());
	EXPECT_EQ(*pos, 2);

	pos = lst.insertNode(lst.end(), 3);
	EXPECT_EQ(pos, --lst.end());
	EXPECT_EQ(*pos, 3);

	pos = lst.begin();
	++pos;
	pos = lst.insertNode(pos, 4);
	EXPECT_EQ(*pos, 4);

	int array[] = {2, 4, 1, 3};
	pos = lst.begin();
	for (int i = 0; i < 4; ++i)
		EXPECT_EQ(*pos++, array[i]);


}

TEST(appendNodeTest, content)
{
	List<int> lst;
	List<int>::iterator pos;

	pos = lst.appendNode(lst.begin(), 1);
	EXPECT_EQ(pos, lst.begin());
	EXPECT_EQ(*lst.begin(), 1);

	pos = lst.appendNode(lst.end(), 2);
	EXPECT_EQ(pos, lst.begin());
	EXPECT_EQ(*lst.begin(), 2);

	pos = lst.appendNode(lst.begin(), 3);
	EXPECT_EQ(pos, ++lst.begin());

	int array[] = { 2, 3, 1};
	pos = lst.begin();
	for (int i = 0; i < 3; ++i)
		EXPECT_EQ(*pos++, array[i]);
}

TEST(removeNodeTest, content)
{
	List<int> lst;
	List<int>::iterator pos;

	pos = lst.removeNode(lst.begin());
	EXPECT_EQ(pos, lst.begin());

	pos = lst.insertNode(lst.begin(), 1);
	EXPECT_EQ(lst.len, 1u);
	pos = lst.removeNode(pos);
	EXPECT_EQ(lst.len, 0u);
	EXPECT_EQ(pos, lst.end());

	pos = lst.insertNode(lst.begin(), 1);
	pos = lst.insertNode(pos, 2);
	pos = lst.removeNode(pos);
	EXPECT_EQ(*pos, 1);
	EXPECT_EQ(lst.len, 1u);
	EXPECT_EQ(*lst.begin(), 1);

}
